package com.example.demo.service.impl;

import com.example.demo.dao.user.UserDao;
import com.example.demo.model.User;
import com.example.demo.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User getUserInfo(String id) {
        if(id==null){
            return null;
        }
        return userDao.getUserId(id);
    }

    @Override
    public boolean insertUser(User user) {
        int i=0;
        if(StringUtils.isNotEmpty(user.getUserName())){
            user.setId(UUID.randomUUID().toString().replace("-",""));
            user.setUserName(user.getUserName());
            user.setRoleId(userDao.getNextRoleId());
            i = userDao.insertUserInfo(user);
        }
        return i==1?true:false;
    }
}
